const service = require('../request').service;
const model = require("../../utils/modelUtil");

/**
 * 环任务
 */
class CircleTask {
    constructor(user) {
        this.user = user;
    }

    /**
     * 接取
     * @param taskID 任务ID
     * @returns {Promise<unknown>}
     */
    accept(taskID) {
        return new Promise((resolve, reject) => {
            service({
                method: 'POST',
                url: this.user.game.reqUrl + '/acceptCircleTask',
                data: model.userModel('acceptCircleTask', {taskID: taskID, flag: 'zntehzd'}, this.user.game.isWeb, this.user.game.data),
            }).then(res => {
                const resData = res.data;
                resolve(resData.code===200?resData.MsgData:{});
            }).catch(err => {
                reject(err);
            })
        })
    }

    /**
     * 完成
     * @param taskID 任务ID
     * @param retData 目标数据
     * @returns {Promise<unknown>}
     */
    complete(taskID, retData) {
        return new Promise((resolve, reject) => {
            service({
                method: 'POST',
                url: this.user.game.reqUrl + '/getCircleTaskAward',
                data: model.userModel('getCircleTaskAward', {taskID: taskID, retData: retData, gTime: this.user.game.data.inGameTime}, this.user.game.isWeb, this.user.game.data),
            }).then(res => {
                const resData = res.data;
                resolve(resData.code===200?resData.MsgData:{});
            }).catch(err => {
                reject(err);
            })
        })
    }
}

module.exports = CircleTask;